package com.info.dpunified.web.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.info.dpunified.defects.DefectsSubmissionStatusSelector;

public class DefectStatusFilterServlet extends HttpServlet{

private static final long serialVersionUID = 1L;
	
	public void doGet(HttpServletRequest request,  
            HttpServletResponse response) throws IOException,  
                                                 ServletException {  
		doPost(request, response);  
	}  

	public void doPost(HttpServletRequest request,HttpServletResponse response)
	throws ServletException, IOException
	{
		
		DefectsSubmissionStatusSelector defectsSubmissionStatusSelector = new DefectsSubmissionStatusSelector();
		
		List<String> years = defectsSubmissionStatusSelector.fetchDefectStatusYears();
		
		if(years == null || years.isEmpty())
		{
			request.setAttribute("defects", "notfound");
			request.setAttribute("defectsnotfound", "No defects submitted");
		}
		
		request.setAttribute("YEAR", years);
		
		
		try {
			getServletConfig().getServletContext().getRequestDispatcher("/jsp/viewdefectssubmission.jsp").forward(request, response);
		} catch (ServletException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
